package com.zhengdongzulin.zuke.app.main.mine.lifeservice

import android.content.Intent
import androidx.fragment.app.Fragment
import com.google.gson.Gson
import com.lxj.androidktx.core.getVM
import com.lxj.androidktx.core.sp
import com.zhengdongzulin.zuke.R
import com.zhengdongzulin.zuke.app.data.ChangeHomeData
import com.zhengdongzulin.zuke.base.BaseActivity
import com.zhengdongzulin.zuke.databinding.ZkActivityLifeServiceBinding
import com.zhengdongzulin.zuke.ext.put
import com.zhengdongzulin.zuke.ext.start

class ZKLifeServiceActivity : BaseActivity<LifeServiceVm,ZkActivityLifeServiceBinding>() {

    var mType: String? = null
    var mHouseId = ""
    var mTabs = arrayOf("全部", "处理中", "待评价")
    var mFragments = arrayListOf<Fragment>()

    override fun getLayoutResId(): Int = R.layout.zk_activity_life_service

    override fun initVM(): LifeServiceVm = getVM(LifeServiceVm::class.java)

    override fun initView() {
        mType = intent.getStringExtra("type")
        mHouseId =
            Gson().fromJson(sp().getString("change_home", ""), ChangeHomeData::class.java).houseId
        setTitleContent(mType + "服务")
        when (mType) {
            "保洁", "维修" -> {
                mView.tvBtn.text = "预约$mType"
            }
            "投诉" -> {
                mView.tvBtn.text = "我要投诉"
            }
        }
        mFragments.add(ZKLifeServiceFragment.newInstance(ZKLifeServiceFragment.LifeServiceType.ALL))
        mFragments.add(ZKLifeServiceFragment.newInstance(ZKLifeServiceFragment.LifeServiceType.IN_PROCESS))
        mFragments.add(ZKLifeServiceFragment.newInstance(ZKLifeServiceFragment.LifeServiceType.TO_BE_EVALUATED))
    }

    override fun initData() {
        mView.tlTabs.setViewPager(mView.vpFragment, mTabs, this, mFragments)
        mView.tlTabs.onPageSelected(0)

    }

    override fun initListener() {
        mView.tvBtn.setOnClickListener {
            Intent().put("type", mType!!).start(this, ZKLifeServiceCreateActivity::class.java)
        }
    }

    override fun startObserve() {

    }

}